package com.unionpay.db;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.unionpay.async.AsyncTask;
import com.unionpay.async.AsyncTaskPool;
import com.unionpay.entity.AnchorrecordEntity;
import com.unionpay.mapper.AnchorrecordEntityMapper;
import com.unionpay.util.StrUtil;

/**
 * anchorrecord表操作
 * 
 * @author 瞿峰
 * @since 2016年5月5日
 */
public class TblAnchorrecord {
	static AnchorrecordEntityMapper mapper = Mybaties.getMapper(AnchorrecordEntityMapper.class);

	public static void save(Integer anchorcofigid, String anchortxid, String bizid, Integer lastid, String input) {
		AnchorrecordEntity entity = new AnchorrecordEntity();
		entity.setAnchorcofigid(anchorcofigid);
		entity.setAnchortxid(anchortxid);
		entity.setBizid(bizid);
		entity.setReccrtts(new Date());
		entity.setLastid(lastid);
		entity.setInput(input);
		mapper.insert(entity);
	}

	public static List<String> getanchorresults(String bizid, String anchorconfigid, String begindate, String enddate) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("bizid", bizid);
		map.put("anchorconfigid", anchorconfigid);
		map.put("begindate", begindate);
		map.put("enddate", enddate);

		return mapper.getanchorresults(map);
	}

	public static AnchorrecordEntity getanchorbytransid(String bizid,String transid) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("transid", transid);
		map.put("bizid", bizid);
		return mapper.getanchorbytransid(map);
	}

	public static void asyncSave(Integer anchorcofigid, String anchortxid, String bizid) {
		String sql = "insert into anchor_cofig(`anchor_cofig_id`,`anchor_txid`,`bizid`,`rec_crt_ts`) value(?,?,?,?)";
		AsyncTask asyncTask = new AsyncTask(sql, new String[] { String.valueOf(anchorcofigid), anchortxid, bizid,
				StrUtil.getDate(new Date()) });
		AsyncTaskPool.add(asyncTask);
	}

	public static void deleteBybizid(String bizid) {
		mapper.deleteBybizid(bizid);
	}
}
